package com.ylxl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylxl.common.annotation.Log;
import com.ylxl.common.enums.BusinessType;
import com.ylxl.common.result.AjaxResult;
import com.ylxl.common.result.BaseController;
import com.ylxl.common.utils.StringUtils;
import com.ylxl.entity.LaborProtection;
import com.ylxl.entity.reponse.EmployeeLaborVO;
import com.ylxl.entity.reponse.LaborProtectionVO;
import com.ylxl.entity.request.*;
import com.ylxl.service.IEmployeeLaborService;
import com.ylxl.service.ILaborProtectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工劳保
 * @Auther Gilbert
 * @Date 2023/6/25 18:53
 */
@Slf4j
@RestController
@RequestMapping("/employeeLabor")
@Api(tags = "员工劳保", hidden = true)
public class EmployeeLaborController extends BaseController {

    @Resource
    private IEmployeeLaborService employeeLaborService;

    /**
     * 分页查询员工劳保列表信息
     * @param queryEmployeeLabor
     * @return
     */
    @Log(title = "分页查询员工劳保列表信息", businessType = BusinessType.SELECT)
    @PostMapping("/queryEmployeeLaborList")
    @ApiOperation(value = "分页查询员工劳保列表信息", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = EmployeeLaborVO.class),})
    public AjaxResult queryLaborProtectionList(@RequestBody QueryEmployeeLabor queryEmployeeLabor) {
        AjaxResult ajax = AjaxResult.success();
        try {
            //进行分页操作
            PageInfo<EmployeeLaborVO> pageInfo = new PageInfo<>();
            if (StringUtils.isNotEmpty(queryEmployeeLabor.getPageNum()) && StringUtils.isNotEmpty(queryEmployeeLabor.getPageSize())) {
                PageHelper.startPage(queryEmployeeLabor.getPageNum(), queryEmployeeLabor.getPageSize());
            }
            List<EmployeeLaborVO> employeeLaborVOList = employeeLaborService.selectLabelList(queryEmployeeLabor);
            pageInfo = new PageInfo<>(employeeLaborVOList);
            ajax.put(AjaxResult.DATA_TAG, employeeLaborVOList);
            ajax.put(AjaxResult.TOTAL, pageInfo.getTotal());
        } catch (Exception e) {
            log.error("查询员工劳保列表日志信息，异常信息：{}", e);
            return toAjax(false);
        }
        return ajax;
    }

    /**
     * 员工劳保保存
     * @param employeeLaborCmdOrMdy
     * @return
     */
    @Log(title = "员工劳保保存", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    @ApiOperation(value = "员工劳保保存", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult add(@RequestBody EmployeeLaborCmdOrMdy employeeLaborCmdOrMdy){
        return toAjax(employeeLaborService.insertLabel(employeeLaborCmdOrMdy));
    }

    /**
     * 员工劳保编辑
     * @param employeeLaborCmdOrMdy
     * @return
     */
    @Log(title = "员工劳保编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation(value = "员工劳保编辑", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult update(@RequestBody EmployeeLaborCmdOrMdy employeeLaborCmdOrMdy){
        return toAjax(employeeLaborService.updateLabel(employeeLaborCmdOrMdy));
    }
    /**
     * 员工劳保根据id查询明细
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "员工劳保根据id查询明细", response = AjaxResult.class)
    @Log(title = "员工劳保根据id查询明细", businessType = BusinessType.SELECT)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = EmployeeLaborVO.class),})
    public AjaxResult getInfo(@PathVariable(value = "id", required = true) Integer id) {
        return AjaxResult.success(employeeLaborService.selctById(id));
    }
    /**
     * 员工劳保根据ids集合删除
     */
    @PostMapping("/remove")
    @ApiOperation(value = "员工劳保根据ids集合删除", response = AjaxResult.class)
    @Log(title = "员工劳保根据ids集合删除", businessType = BusinessType.DELETE)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult remove(@RequestBody DeleteRequest deleteRequest) {
        return AjaxResult.success(employeeLaborService.deleteByIds(deleteRequest.getIds()));
    }
}
